﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace TheFinalCountDown
{
	public class CountDown
	{
		private DateTime targetDate;
		private TimeSpan timeLeft;

		public CountDown(DateTime destinationDate)
		{
			this.targetDate = destinationDate;
		}

		public void Update()
		{
			timeLeft = targetDate - DateTime.Now;
			
			if (UserSettings.Instance.IsEffectiveTime)
			{
				Calendar c = CultureInfo.InvariantCulture.Calendar;
				TimeSpan oneDay = new TimeSpan(1, 0, 0, 0);
				TimeSpan nonWorkTime = new TimeSpan(0, 16, 0, 0);

				for (DateTime temp = DateTime.Now; temp < targetDate; temp = temp.Add(oneDay))
				{
					DayOfWeek dayOfWeek = c.GetDayOfWeek(temp);

					if (dayOfWeek == DayOfWeek.Saturday || dayOfWeek == DayOfWeek.Sunday)
					{
						//timeLeft = timeLeft.Subtract(oneDay);
					}
					else
					{
						timeLeft = timeLeft.Subtract(nonWorkTime);
					}
				}
			}
		}

		#region Get and Set Functions

		public TimeSpan TimeLeft
		{
			get { return timeLeft; }
		}

		public DateTime TargetDate
		{
			get { return targetDate; }
			set { targetDate = value; }
		}

		#endregion
	}
}
